Imports DotNetPm.Business.Questionnaire

Partial Class Modules_Questionnaires_Controls_logMultipleChoicesSingleAnswer
    Inherits System.Web.UI.UserControl
    Implements UserControls.ILogicUC

    Dim _question As Question

    Public Property Logic() As String Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Logic
        Get
            Return "5|" & ddlOperators.SelectedIndex _
            & "|" & rblChoices.SelectedIndex & "|" & ddlAnswer.SelectedValue
        End Get
        Set(ByVal value As String)
            Dim val As String() = value.Split("|")
            ddlOperators.SelectedIndex = val(1)
            rblChoices.SelectedIndex = val(2)
            ddlAnswer.SelectedValue = val(3)
        End Set
    End Property

    Public Property Question() As Question Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Question
        Get
            Return _question
        End Get
        Set(ByVal value As Question)
            _question = value
        End Set
    End Property

    Public Sub Reset() Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Reset
        ddlOperators.SelectedIndex = -1
        rblChoices.SelectedIndex = -1
    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        PopulateChoices()
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        AdjustControls()
    End Sub

    Private Sub AdjustControls()
        Select Case ddlAnswer.SelectedIndex
            Case 0  '-1
                rblChoices.Visible = False
                reqChoices.Visible = False
                rblChoices.Visible = False
                ddlOperators.Visible = False
            Case 1  ' 0
                PopulateChoices()
                reqChoices.Visible = True
                rblChoices.Visible = True
                ddlOperators.Visible = True
        End Select
    End Sub

    Private Sub PopulateChoices()
        With rblChoices
            .Visible = True
            .DataSource = QuestionODS.GetChoices(_question.ID)
            .DataTextField = "Choice"
            .DataValueField = "SortID"
            .DataBind()
        End With
    End Sub

End Class
